﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using System.Data.Objects.DataClasses;
using System.Data;

namespace DocumentManagement.Models
{
    public enum YuGuDanState : int
    {
        WeiChuLi,
        AssignedToEmployeeToGetReport,
        AssignedToEmployeeToCharge,
        DocumentedDirectly,
        DoneConfirm,
    }

    public enum BaoGaoState : int
    {
        RequireUpdate,
        Audit1,
        Audit2,
        Audit3,
        NeedToAssignToChargeMoney,
        AssignToEmployeeToChargeMoney,
        DoneConfirm
    }

    [Flags]
    public enum PermissionLevel : int
    {
        None = 0,

        AccountNormal = 1,

        YuGuDanOperationList = 2,
        YuGuDanCreate = 4,
        YuGuDanAssgin = 8,
        YuGuDanToReportProcess = 16,
        YuGuDanViewDetail = 32,
        YuGuDanSearch = 64,

        BaoGaoOperationList = 128,
        BaoGaoCreate = 256,
        BaoGaoUpdate = 512,
        BaoGaoViewDetail = 1024,
        BaoGaoAudit1 = 2048,
        BaoGaoAudit2 = 4096,
        BaoGaoAudit3 = 8192,
        BaoGaoAttachmentDownload = 16384,
        BaoGaoSearch = 32768,
        BaoGaoAfterAuditProcess = 65536,

        TollOperationList = 131072,
        ChargeFromYuGuDan = 262144,
        ChargeFromGaoGao = 524288,
        ConfirmCharge = 1048576,

        YuGuDanEdit = 2097152,

        Special = 4194304,

    }

    public class Consts
    {
        public const string UidSessionKey = "uid";
    }

    public enum HuanXianQuYu
    {
        NeiHuan,
        NeiZhong,
        ZhongWai,
        Wai
    }

    public enum YeTai
    {
        ZhuZhai,
        GongYe,
        ShangYe,
        BanGong,
        QiTa,
    }

    public static class Utility
    {
        public static string GetEnumText(BaoGaoState bgs)
        {
            switch (bgs)
            {
                case BaoGaoState.AssignToEmployeeToChargeMoney:
                    return "收费中";
                case BaoGaoState.Audit1:
                    return "一审";
                case BaoGaoState.Audit2:
                    return "二审";
                case BaoGaoState.Audit3:
                    return "三审";
                case BaoGaoState.RequireUpdate:
                    return "审批失败，需要重新更新";
                case BaoGaoState.NeedToAssignToChargeMoney:
                    return "需要收费";
                case BaoGaoState.DoneConfirm:
                    return "收费完成";
                default:
                    throw new InvalidOperationException("错误的报告状态");
            }
        }

        public static string GetEnumText(HuanXianQuYu hxqy)
        {
            switch(hxqy)
            {
                case HuanXianQuYu.NeiHuan:
                    return "内环";
                case HuanXianQuYu.NeiZhong:
                    return "内中环";
                case HuanXianQuYu.Wai:
                    return "外环";
                case HuanXianQuYu.ZhongWai:
                    return "中外环";
                default:
                    throw new InvalidOperationException("不支持该环线区域");
            }
        }

        public static string GetEnumText(YeTai yt)
        {
            switch(yt)
            {
                case YeTai.BanGong:
                    return "办公";
                case YeTai.GongYe:
                    return "工业";
                case YeTai.QiTa:
                    return "其他";
                case YeTai.ShangYe:
                    return "商业";
                case YeTai.ZhuZhai:
                    return "住宅";
                default:
                    throw new InvalidOperationException("不支持该业态");
            }
        }

        public static string GetEnumText(YuGuDanState ygdzt)
        {
            switch(ygdzt)
            {
                case YuGuDanState.WeiChuLi:
                    return "未处理";
                case YuGuDanState.DocumentedDirectly:
                    return "直接归档";
                case YuGuDanState.AssignedToEmployeeToGetReport:
                    return "分配给员工做报告";
                case YuGuDanState.AssignedToEmployeeToCharge:
                    return "直接分配给员工收费";
                case YuGuDanState.DoneConfirm:
                    return "收费完成";
                default:
                    throw new InvalidOperationException("不支持该预估单状态");
            }

        }

        public static object GetKeyValueByName(this EntityKey entityKey, string memberName)
        {

            foreach (EntityKeyMember member in entityKey.EntityKeyValues)
            {

                if (member.Key == memberName)
                {

                    return member.Value;

                }

            }

            throw new ArgumentException("The key name provided does not match a member of the EntityKey");

        }
    }

}
